package com.nicolas.pattern.responsibilitychain;

/**
 * 职责链模式(Chain of Responsibility Pattern)：避免请求发送者与接收者耦合在一起，让多个对象都有可能接收请求，
 * 将这些对象连接成一条链，并且沿着这条链传递请求，直到有对象处理它为止。职责链模式是一种对象行为型模式。
 * @author nicolas  2017年2月12日 -- 下午5:06:19
 */
public class ResponsibilitychainMain {
	 public static void main(String[] args) {  
        Approver wjzhang,gyang,jguo,meeting;  
        wjzhang = new Director("张无忌");  
        gyang = new VicePresident("杨过");  
        jguo = new President("郭靖");  
        meeting = new Congress("董事会");  
      
        Approver rhuang;  
        rhuang = new Manager("黄蓉");
        
        //创建职责链  
        wjzhang.setSuccessor(rhuang); //将“黄蓉”作为“张无忌”的下家  
        rhuang.setSuccessor(gyang); //将“杨过”作为“黄蓉”的下家  
        gyang.setSuccessor(jguo);  
        gyang.setSuccessor(jguo);  
        jguo.setSuccessor(meeting);  
          
        //创建采购单  
        PurchaseRequest pr1 = new PurchaseRequest(45000,10001,"购买倚天剑");  
        wjzhang.processRequest(pr1);  
          
        PurchaseRequest pr2 = new PurchaseRequest(60000,10002,"购买《葵花宝典》");  
        wjzhang.processRequest(pr2);  
      
        PurchaseRequest pr3 = new PurchaseRequest(160000,10003,"购买《金刚经》");  
        wjzhang.processRequest(pr3);  
  
        PurchaseRequest pr4 = new PurchaseRequest(800000,10004,"购买桃花岛");  
        wjzhang.processRequest(pr4);  
    }  
}
